<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link rel="stylesheet" href="./zhuce.css" type="text/css">
</head>
<body>
<form id="form"  name="form2" action="./index.html" >
    <table id="table_zhu" >
        <tr>
            <td></td> <td id="ti">欢迎注册知识管理系统</td>
        </tr>
        <tr>
            <th class="t1">姓名：</th><td><input type="text" id="username" class="text"  ></td>
        </tr>
        <tr>
            <td class="zhu"></td> <td class="zhu">请输入4到16位（字母，数字，下划线，减号）用户名</td>
        </tr>
        <tr>
            <th class="t1">手机：</th><td><input type="text" id="phone"class="text" ></td>
        </tr>
        <tr>
            <td class="zhu"></td> <td class="zhu">请输入合法的手机号</td>
        </tr>
        <tr>
            <th class="t1">身份证：</th><td><input type="password" id="card" class="text"></td>
        </tr>
        <tr>
            <td class="zhu"></td> <td class="zhu">输入合法身份证号</td>
        </tr>
        <tr>
            <th class="t1">密码：</th><td><input type="password" id="pwd1" class="text" ></td>
        </tr>
        <tr>
            <td class="zhu"></td> <td class="zhu">密码由6-21字母和数字组成，不能是纯数字或纯英文</td>
        </tr>
        <tr>
            <th class="t1">确认密码：</th><td><input type="password" id="pwd2" class="text" ></td>
        </tr>
        <tr>
            <td class="zhu"></td> <td class="zhu">输入相同的密码</td>
        </tr>
        <tr>
            <th colspan="2"><input type="button" value="注册" class="b1" onclick="sub()" />
                <input type="reset" value="重写"class="b1"></th>
        </tr>
    </table>


</form>
    <script>
        console.log(document.getElementById("username"));
        function sub() {
            var username=document.getElementById("username").value;
            var phone=document.getElementById("phone").value;
            var card=document.getElementById("card").value;
            var pwd1=document.getElementById("pwd1").value;
            var pwd2=document.getElementById("pwd2").value;
            //用户名正则，4到16位（字母，数字，下划线，减号）
            var un = /^[a-zA-Z0-9_-]{4,16}$/;

            //手机号正则
            var phons = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$/;

            //身份证号（18位）正则
            var cs =/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;

            //密码由6-21字母和数字组成，不能是纯数字或纯英文
            var pwds = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,21}$/;

            if(!un.test(username)){
                alert("要输入合法用户名哦！")
            }else if(!phons.test(phone)){
                alert("要输入合法的手机号哦！")
            }else if(!cs.test(card)){
                alert("输入身份证不合法哟！")
            }else if(!pwds.test(pwd1)){
                alert("密码不合法辣")
            }else if(pwd2!=pwd1){
                alert("两次输入密码不一样哟！")
            }else {
              document.getElementById("form").submit();
            }

        }
    </script>

</body>
</html>